/**
 * 初始化RMB银行其它收入/其它支出明细详情对话框
 */
var RmbCashReceiptsInfoDlg = {
    rmbCashReceiptsInfoData : {}
};

/**
 * 清除数据
 */
RmbCashReceiptsInfoDlg.clearData = function() {
    this.rmbCashReceiptsInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
RmbCashReceiptsInfoDlg.set = function(key, val) {
    this.rmbCashReceiptsInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
RmbCashReceiptsInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
RmbCashReceiptsInfoDlg.close = function() {
    parent.layer.close(window.parent.RmbCashReceipts.layerIndex);
}

/**
 * 收集数据
 */
RmbCashReceiptsInfoDlg.collectData = function() {
    this
    .set('id')
    .set('summary')
    .set('customer')
    .set('amount')
    .set('type')
    .set('revdate')
    .set('platform')
    .set('note')
    .set('creattime')
    .set('updatetime');
}

/**
 * 提交添加
 */
RmbCashReceiptsInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();
    ;

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/rmbCashReceipts/add", function(data){

        Feng.success("添加成功!");
        window.parent.RmbCashReceipts.table.refresh();
        RmbCashReceiptsInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.rmbCashReceiptsInfoData);
    ajax.start();
}

/**
 * 导出
 */
RmbCashReceiptsInfoDlg.rmbCashReceiptsExport = function(){
    var revDate = $("#revDate").val();
    if(revDate=='' || revDate==undefined    ){
        layer.open({
            content: '请选择导出时间!'
        });
        return;
    }
    window.location="/rmbCashReceipts/load?beginDate="+$("#beginDate").val()+"&endDate="+$("#endDate").val()+"&type="+$("#type").val();


}



/**
 * 提交修改
 */
RmbCashReceiptsInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/rmbCashReceipts/update", function(data){
        Feng.success("修改成功!");
        window.parent.RmbCashReceipts.table.refresh();
        RmbCashReceiptsInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.rmbCashReceiptsInfoData);
    ajax.start();
}


/**
 * 选中事件
 */
RmbCashReceiptsInfoDlg.getChange = function (){
    var opt=$("#summary").val();
    if(opt==16 || opt==17 ){
        $("#customerdiv").show();
    }else{
        $("#customerdiv").hide();
    }

}

RmbCashReceiptsInfoDlg.getSelectDetails = function(){
    var opt=$("#summary").val();
    var detailsType=$("#detailsType").val();
    var channel=$("#summary").find("option");
    if($("#summary")[0].details==undefined){
        $("#summary")[0].details=channel;
    }
    if(detailsType=="1"){
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        var details=$("#summary")[0].details;
        for (var i=0;i<details.length;i++){
            if (details[i].getAttribute("valueType") == detailsType){
                $("#summary").append(details[i].outerHTML);
            }
        }

    }else if (detailsType=="2") {//支出
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        var details=$("#summary")[0].details;
        for (var i=0;i<details.length;i++){
            if (details[i].getAttribute("valueType") == detailsType){
                $("#summary").append(details[i].outerHTML);
            }
        }
    }else if (detailsType=="3") {//应收应付
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        var details=$("#summary")[0].details;
        for (var i=0;i<details.length;i++){
            if (details[i].getAttribute("valueType") == detailsType&&details[i].getAttribute("value")=='16'){//应收
                $("#summary").append(details[i].outerHTML);
            }
        }
    }else if (detailsType=="4") {//支出
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        var details=$("#summary")[0].details;
        for (var i=0;i<details.length;i++){
            if (details[i].getAttribute("valueType") == detailsType){
                $("#summary").append(details[i].outerHTML);
            }
        }
    }else if (detailsType=="5") {//支出
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        var details=$("#summary")[0].details;
        for (var i=0;i<details.length;i++){
            if (details[i].getAttribute("valueType") == detailsType){
                $("#summary").append(details[i].outerHTML);
            }
        }
    }else if (detailsType=="6") {//支出
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        var details=$("#summary")[0].details;
        for (var i=0;i<details.length;i++){
            if (details[i].getAttribute("valueType")  == detailsType){
                $("#summary").append(details[i].outerHTML);
            }
        }
    }else if (detailsType=="8") {//收入
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        var details=$("#summary")[0].details;
        ;
        for (var i=0;i<details.length;i++){
            if (details[i].getAttribute("valueType") == detailsType||details[i].getAttribute("value")=='17'){//应付
                $("#summary").append(details[i].outerHTML);
            }
        }
    }
    RmbCashReceiptsInfoDlg.getChange();
}


RmbCashReceiptsInfoDlg.getSelectDetailsType = function(){
    var opt=$("#detailsType").val();
    var type=$("#type").val();
    var channel=$("#detailsType").find("option");
    if($("#detailsType")[0].code==undefined){
        $("#detailsType")[0].code=channel;
    }
    ;
    //收入
    if(type=="1"){
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        $("#detailsType").append("<option selected='true' value='8'>收入</option>");
    }else{//支出
        for(var i=0;i<channel.length;i++){
            channel[i].remove();
        }
        var code=$("#detailsType")[0].code;
        for (var i=0;i<code.length;i++){
            if(code[i].value!='7'&&code[i].value!='8'){
                $("#detailsType").append(code[i].outerHTML);
            }

        }
    }
    RmbCashReceiptsInfoDlg.getSelectDetails ();
}

$(function() {
    RmbCashReceiptsInfoDlg.getSelectDetailsType();

});


